<?php
class cache{
    private $directrory = './cache/';
    private $ext = '.cache';
	private $name;

    function __construct($name){
        ob_start();
		$this->name = $name;
    }

    public function create($content){
        $fh = fopen($this->directory . $this->name . $this->ext, 'w+');
        fwrite($fh, $content);
        fclose($fh);
    }

    public function is_cached(){
        return file_exists($this->directory . $this->name . $this->ext);
    }

    public function load(){
        if($this->is_cached()){
            print file_get_contents($this->directory . $this->name . $this->ext);
            return true;
        }
        return false;
    }

    public function delete($sf){
        return unlink($this->directory . $this->name . $this->ext);
    }

	public function deleteAll(){
		if($file = glob( $this->directory . '*.cache' ))
			foreach( $file as $delfile)
				unlink($delfile);
	}

    public function end(){
		$this->createCache(ob_get_contents());
        ob_end_flush();
    }
}
?>